export const token = {
	set: (data, expires_in) => {
		uni.setStorageSync("token", data)
		uni.setStorageSync("expires_in", expires_in)
	},
	get: () => {
		if (Date.parse(new Date()) > uni.getStorageSync("expires_in")) {
			token.clear()
			userInfo.clear()
			return false
		} else {
			return uni.getStorageSync("token")
		}
	},
	clear: () => {
		uni.removeStorageSync("token")
		uni.removeStorageSync("expires_in")
	}
}

export const userInfo = {
	set: (data, expires_in) => {
		uni.setStorageSync("userInfo", JSON.stringify(data))
		uni.setStorageSync("expires_in", expires_in)
	},
	get: () => {
		if (Date.parse(new Date()) > uni.getStorageSync("expires_in")) {
			return false
		} else {
			return JSON.parse(uni.getStorageSync("userInfo")) 
		}
	},
	clear: () => {
		uni.removeStorageSync("userInfo")
		uni.removeStorageSync("expires_in")
	}
}

export const doctorInfo = {
	set: (data, expires_in) => {
		uni.setStorageSync("doctorInfo", JSON.stringify(data))
		uni.setStorageSync("expires_in", expires_in)
	},
	get: () => {
		if (Date.parse(new Date()) > uni.getStorageSync("expires_in")) {
			return false
		} else {
			return JSON.parse(uni.getStorageSync("doctorInfo")) 
		}
	},
	clear: () => {
		uni.removeStorageSync("doctorInfo")
		uni.removeStorageSync("expires_in")
	}
}

export const imInfo = {
	set: (data, expires_in) => {
		uni.setStorageSync("imInfo", JSON.stringify(data) )
		uni.setStorageSync("expires_in", expires_in)
	},
	get: () => {
		if (Date.parse(new Date()) > uni.getStorageSync("expires_in")) {
			return false
		} else {
			return JSON.parse(uni.getStorageSync("imInfo"))
		}
	},
	clear: () => {
		uni.removeStorageSync("imInfo")
		uni.removeStorageSync("expires_in")
	}
}

export const currentImInfo = {
	set: (data, expires_in) => {
		uni.setStorageSync("currentImInfo", JSON.stringify(data) )
		uni.setStorageSync("expires_in", expires_in)
	},
	get: () => {
		if (Date.parse(new Date()) > uni.getStorageSync("expires_in")) {
			return false
		} else {
			return JSON.parse(uni.getStorageSync("currentImInfo"))
		}
	},
	clear: () => {
		uni.removeStorageSync("currentImInfo")
		uni.removeStorageSync("expires_in")
	}
}

export const searchHistory ={
	set:(data) => {
		uni.setStorageSync("search_history", data)
	},
	get:()=>{
		return uni.getStorageSync("search_history")
	},
	clear:()=>{
		uni.removeStorageSync("search_history")
	}
}